//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include "win32.h"
#include "aura.h"

EXTERN_C Aura_PVoid CDECL
Aura_malloc(
    /* [in] */ Aura_Int32 size)
{
    return (void *)CoTaskMemAlloc((ULONG)size);
}

EXTERN_C Aura_PVoid CDECL
Aura_realloc(
    /* [in] */ Aura_PVoid  p,
    /* [in] */ Aura_Int32 size)
{
    return (void *)CoTaskMemRealloc((LPVOID)p,(ULONG)size);
}

EXTERN_C Aura_Void CDECL
Aura_free(
    /* [in] */ Aura_PVoid p)
{
    CoTaskMemFree((LPVOID)p);
    return ;
}

EXTERN_C Aura_Int32 CDECL
Aura_putws(
    /* [in] */ const Aura_PWChar wstr)
{
    return _putws((wchar_t *)wstr);
}

EXTERN_C Aura_Int32 CDECL
Aura_printf(
    /* [in] */ const Aura_PChar format,...)
{
    va_list args;
    int len;

    va_start(args, format);
    len = vprintf(format, args);
    va_end(args);

    return len;
}

EXTERN_C Aura_Int32 CDECL
Aura_vprintf(
    /* [in] */ const Aura_PChar format,
    /* [in] */ Aura_PUChar args)
{
    return vprintf(format, args);
}

EXTERN_C Aura_Int32 CDECL
Aura_swprintf(
    /* [in] */ Aura_PWChar buf,
    /* [in] */Aura_WChar const *fmt,...)
{
    int len;
    va_list ap;

    va_start (ap, fmt);
    len = _vsnwprintf((wchar_t *)buf, 0x7fffffff, (wchar_t *)fmt, ap);
    va_end (ap);

    return len;
}

EXTERN_C Aura_PWChar CDECL
Aura_fullpath(
    /* [in]  */ Aura_PWChar fullPath,
    /* [in]  */ const Aura_PWChar curPath,
    /* [in]  */ Aura_Int32 n_Size)
{
    return (Aura_PWChar)_wfullpath((wchar_t *)fullPath, (wchar_t *)curPath, n_Size);
}

EXTERN_C Aura_PWChar CDECL
Aura_wcschr(const Aura_PWChar str, Aura_WChar c)
{
    return (Aura_PWChar)wcschr((wchar_t *)str, c);
}

EXTERN_C Aura_PWChar CDECL
Aura_wcsrchr(const Aura_PWChar str, Aura_WChar c)
{
    return (Aura_PWChar)wcsrchr((wchar_t *)str, c);
}

EXTERN_C Aura_Int32 CDECL Aura_getchar()
{
    return (Aura_Int32)getchar();
}

EXTERN_C Aura_PVoid CDECL
Aura_memcpy(Aura_PVoid dest, const Aura_PVoid src, Aura_Int32 count)
{
    return memcpy(dest, src, (size_t)count);
}
